package com.abcode.test.springbootmybatisplus.gen.controller;


import cn.hutool.core.util.ObjectUtil;
import com.abcode.test.springbootmybatisplus.gen.common.PageUtil;
import com.abcode.test.springbootmybatisplus.gen.common.Result;
import com.abcode.test.springbootmybatisplus.gen.entity.UserDetailsInfo;
import com.abcode.test.springbootmybatisplus.gen.param.UserDetailsInfoParam;
import com.abcode.test.springbootmybatisplus.gen.service.UserDetailsInfoService;
import com.abcode.test.springbootmybatisplus.gen.vo.UserDetailsInfoVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 德州扑克用户详细信息表(UserDetailsInfo)表控制层
 *
 * @author abcode
 * @since 2025-06-27 23:27:19
 */
@Api(tags = "德州扑克用户详细信息表")
@RestController
@RequestMapping("/userDetailsInfo")
public class UserDetailsInfoController {

    @Resource
    private UserDetailsInfoService userDetailsInfoService;

    /**
     * 分页查询德州扑克用户详细信息表
     *
     * @param param 参数对象
     * @return
     */
    @ApiOperation(value = "分页查询德州扑克用户详细信息表", notes = "分页查询德州扑克用户详细信息表")
    @PostMapping("/pageQuery")
    public Result<IPage<UserDetailsInfoVO>> pageQuery(@RequestBody @Validated(UserDetailsInfoParam.QueryGroup.class) UserDetailsInfoParam param) {
        IPage selectPage = userDetailsInfoService.pageQuery(param);
        IPage resultPage = PageUtil.convert(UserDetailsInfoVO.class, selectPage);
        return Result.ok(resultPage);
    }

    /**
     * 条件查询德州扑克用户详细信息表
     *
     * @param param 参数对象
     * @return
     */
    @ApiOperation(value = "条件查询德州扑克用户详细信息表", notes = "条件查询德州扑克用户详细信息表")
    @PostMapping("/listQuery")
    public Result<List<UserDetailsInfoVO>> listQuery(@RequestBody @Validated(UserDetailsInfoParam.QueryGroup.class) UserDetailsInfoParam param) {
        List<UserDetailsInfo> selectList = userDetailsInfoService.listQuery(param);
        List<UserDetailsInfoVO> list = selectList.stream().map(UserDetailsInfoVO::new).collect(Collectors.toList());
        return Result.ok(list);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param param 主键
     * @return 单条数据
     */
    @ApiOperation(value = "通过主键查询单条数据", notes = "通过主键查询单条数据")
    @PostMapping("/queryById")
    public Result<UserDetailsInfoVO> selectOne(@RequestBody @Validated(UserDetailsInfoParam.QueryGroup.class) UserDetailsInfoParam param) {
        UserDetailsInfo userDetailsInfo = userDetailsInfoService.getById(param.getUserId());
        UserDetailsInfoVO userDetailsInfoVO = null;
        if (ObjectUtil.isNotEmpty(userDetailsInfo)) {
            userDetailsInfoVO = new UserDetailsInfoVO(userDetailsInfo);
        }
        return Result.ok(userDetailsInfoVO);
    }

    /**
     * 新增德州扑克用户详细信息表
     *
     * @param param 参数对象
     * @return
     */
    @ApiOperation(value = "新增德州扑克用户详细信息表", notes = "新增德州扑克用户详细信息表")
    @PostMapping("/add")
    public Result<String> insert(@RequestBody @Validated(UserDetailsInfoParam.AddGroup.class) UserDetailsInfoParam param) {
        boolean result = userDetailsInfoService.add(param);
        return result ? Result.OK("添加成功") : Result.error("添加失败");
    }

    /**
     * 修改德州扑克用户详细信息表
     *
     * @param param 参数对象
     * @return 修改结果
     */
    @ApiOperation(value = "修改德州扑克用户详细信息表", notes = "修改德州扑克用户详细信息表")
    @PostMapping("/edit")
    public Result<Boolean> update(@RequestBody @Validated(UserDetailsInfoParam.EditGroup.class) UserDetailsInfoParam param) {
        boolean result = userDetailsInfoService.edit(param);
        return result ? Result.OK("修改成功") : Result.error("修改失败");
    }

    /**
     * 批量删除数据
     *
     * @param idListMap 参数对象
     * @return 删除结果
     */
//    @ApiOperation(value = "批量删除数据", notes = "批量删除数据")
//    @PostMapping("/delete")
//    public Result<Boolean> delete(@RequestBody Map<String, Object> idListMap) {
//        String idKey = "ids";
//        if (CollectionUtils.isEmpty(idListMap) || ObjectUtils.isEmpty(idListMap.get(idKey))) {
//            return Result.error("参数不能为空");
//        }
//        List<String> idList = (List<String>) idListMap.get(idKey);
//        boolean result = userDetailsInfoService.removeBatchByIds(idList);
//        return result ? Result.OK(CommonConstant.DB_DELETE_SUCCESS) : Result.error(CommonConstant.DB_DELETE_FAIL);
//    }
}

